
// ***********************************************************************
// AUTO GENERATED CLASS - Do Not Modify this file, if needed modify .tt
// ***********************************************************************
// Assembly         : InnovaApp_DomainLayer
// Author           : LJO+01
// Created          : 17/11/2013 20:29:50
// ***********************************************************************
// <copyright file="N.A." company="Copyright © Innovacall 2011">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary>
// Domain layer  
// DomainClass
// </summary>
// ***********************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;


namespace InnovaApp.Layers.DomainLayer
{
    /// <summary>
    /// Class ArticleComment
    /// </summary>
    [Serializable]
    public partial class ArticleComment : _DomainLayer_Base  
    {
        #region Primitive Properties
    	
        /// <summary>
        /// Gets or sets Id.
        /// </summary>
        /// <value>The Id.</value>
        /// <remarks>
        /// Foregn key of ArticleComment
        /// 
        /// </remarks>
        public virtual int Id
        {
            get { return _id; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_id != value)
                    {
                        if (ManagedContent != null && ManagedContent.Id != value)
                        {
                            ManagedContent = null;
                        }
                        _id = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private int _id;
    	
        /// <summary>
        /// Gets or sets FK_ArticleComment.
        /// </summary>
        /// <value>The FK_ArticleComment.</value>
        /// <remarks>
        /// Foregn key of ArticleComment1
        /// 
        /// </remarks>
        public virtual Nullable<int> FK_ArticleComment
        {
            get { return _fK_ArticleComment; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_ArticleComment != value)
                    {
                        if (ArticleComment2 != null && ArticleComment2.Id != value)
                        {
                            ArticleComment2 = null;
                        }
                        _fK_ArticleComment = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private Nullable<int> _fK_ArticleComment;
    	
        /// <summary>
        /// Gets or sets FK_Article.
        /// </summary>
        /// <value>The FK_Article.</value>
        /// <remarks>
        /// Foregn key of ArticleComment
        /// 
        /// </remarks>
        public virtual int FK_Article
        {
            get { return _fK_Article; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_Article != value)
                    {
                        if (Article != null && Article.Id != value)
                        {
                            Article = null;
                        }
                        _fK_Article = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private int _fK_Article;
    	
        /// <summary>
        /// Gets or sets FK_ManagedContent.
        /// </summary>
        /// <value>The FK_ManagedContent.</value>
        public virtual int FK_ManagedContent
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets FK_Contact.
        /// </summary>
        /// <value>The FK_Contact.</value>
        /// <remarks>
        /// Foregn key of ArticleComment
        /// 
        /// </remarks>
        public virtual int FK_Contact
        {
            get { return _fK_Contact; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_Contact != value)
                    {
                        if (Contact != null && Contact.Id != value)
                        {
                            Contact = null;
                        }
                        _fK_Contact = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private int _fK_Contact;
    	
        /// <summary>
        /// Gets or sets Likes.
        /// </summary>
        /// <value>The Likes.</value>
        public virtual Nullable<int> Likes
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets Unlike.
        /// </summary>
        /// <value>The Unlike.</value>
        public virtual Nullable<int> Unlike
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets Read.
        /// </summary>
        /// <value>The Read.</value>
        public virtual Nullable<bool> Read
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets rowversion.
        /// </summary>
        /// <value>The rowversion.</value>
        public virtual byte[] rowversion
        {
            get;
            set;
        }

        #endregion

        #region Navigation Properties
        public virtual Contact Contact
        {
            get { return _contact; }
            set
            {
                if (!ReferenceEquals(_contact, value))
                {
                    var previousValue = _contact;
                    _contact = value;
                    FixupContact(previousValue);
                }
            }
        }
        private Contact _contact;
        public virtual Article Article
        {
            get { return _article; }
            set
            {
                if (!ReferenceEquals(_article, value))
                {
                    var previousValue = _article;
                    _article = value;
                    FixupArticle(previousValue);
                }
            }
        }
        private Article _article;
    
        /// <summary>
        /// Link ArticleComment to all ArticleComment1
        /// </summary>
        public virtual ICollection<ArticleComment> ArticleComment1
        {
            get
            {
                if (_articleComment1 == null)
                {
                    var newCollection = new FixupCollection<ArticleComment>();
                    newCollection.CollectionChanged += FixupArticleComment1;
                    _articleComment1 = newCollection;
                }
                return _articleComment1;
            }
            set
            {
                if (!ReferenceEquals(_articleComment1, value))
                {
                    var previousValue = _articleComment1 as FixupCollection<ArticleComment>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupArticleComment1;
                    }
                    _articleComment1 = value;
                    var newValue = value as FixupCollection<ArticleComment>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupArticleComment1;
                    }
                }
            }
        }
        private ICollection<ArticleComment> _articleComment1;
        public virtual ArticleComment ArticleComment2
        {
            get { return _articleComment2; }
            set
            {
                if (!ReferenceEquals(_articleComment2, value))
                {
                    var previousValue = _articleComment2;
                    _articleComment2 = value;
                    FixupArticleComment2(previousValue);
                }
            }
        }
        private ArticleComment _articleComment2;
        public virtual ManagedContent ManagedContent
        {
            get { return _managedContent; }
            set
            {
                if (!ReferenceEquals(_managedContent, value))
                {
                    var previousValue = _managedContent;
                    _managedContent = value;
                    FixupManagedContent(previousValue);
                }
            }
        }
        private ManagedContent _managedContent;

        #endregion

        #region Association Fixup
    
        private bool _settingFK = false;
    
        private void FixupContact(Contact previousValue)
        {
            if (previousValue != null && previousValue.ArticleComment.Contains(this))
            {
                previousValue.ArticleComment.Remove(this);
            }
    
            if (Contact != null)
            {
                if (!Contact.ArticleComment.Contains(this))
                {
                    Contact.ArticleComment.Add(this);
                }
                if (FK_Contact != Contact.Id)
                {
                    FK_Contact = Contact.Id;
                }
            }
        }
    
        private void FixupArticle(Article previousValue)
        {
            if (previousValue != null && previousValue.ArticleComment.Contains(this))
            {
                previousValue.ArticleComment.Remove(this);
            }
    
            if (Article != null)
            {
                if (!Article.ArticleComment.Contains(this))
                {
                    Article.ArticleComment.Add(this);
                }
                if (FK_Article != Article.Id)
                {
                    FK_Article = Article.Id;
                }
            }
        }
    
        private void FixupArticleComment2(ArticleComment previousValue)
        {
            if (previousValue != null && previousValue.ArticleComment1.Contains(this))
            {
                previousValue.ArticleComment1.Remove(this);
            }
    
            if (ArticleComment2 != null)
            {
                if (!ArticleComment2.ArticleComment1.Contains(this))
                {
                    ArticleComment2.ArticleComment1.Add(this);
                }
                if (FK_ArticleComment != ArticleComment2.Id)
                {
                    FK_ArticleComment = ArticleComment2.Id;
                }
            }
            else if (!_settingFK)
            {
                FK_ArticleComment = null;
            }
        }
    
        private void FixupManagedContent(ManagedContent previousValue)
        {
            if (previousValue != null && ReferenceEquals(previousValue.ArticleComment, this))
            {
                previousValue.ArticleComment = null;
            }
    
            if (ManagedContent != null)
            {
                ManagedContent.ArticleComment = this;
                if (Id != ManagedContent.Id)
                {
                    Id = ManagedContent.Id;
                }
            }
        }
    
        private void FixupArticleComment1(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (ArticleComment item in e.NewItems)
                {
                    item.ArticleComment2 = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (ArticleComment item in e.OldItems)
                {
                    if (ReferenceEquals(item.ArticleComment2, this))
                    {
                        item.ArticleComment2 = null;
                    }
                }
            }
        }

        #endregion

    }
}
